package genealogy.depricated.loaders;

import java.io.File;
import java.util.Map;

import org.dftproject.lineagelinkage.metric.PedigreeScore;
import org.dftproject.lineagelinkage.metric.PedigreeTarget;

import edu.byu.cs.dml.recordlinkage.comparison.PairDataLoader;
import edu.byu.cs.dml.recordlinkage.pedigree.Pair;
import genealogy.deprecated.datamodel.pedigree.Individual;
import genealogy.deprecated.datamodel.pedigree.PedigreePair;

/**
 * @author Steve
 * @invariant
 */
public class FhdPairsLoader {

	Map<Integer, Pair> m_pairsMap;

	/**
	 * Constructor
	 * 
	 * @param file
	 * @pre
	 * @post the object is created
	 */
	public FhdPairsLoader() {
		m_pairsMap = null;
	}

	/**
	 * @param FHDPairsDir
	 * @pre
	 * @post
	 */
	public void load(File FHDPairsDir) {
		m_pairsMap = PairDataLoader.getPairsMap(FHDPairsDir.getAbsolutePath());
	}

	public Pair getFhdPair(int indexId) {
		if (m_pairsMap == null)
			return null;
		return m_pairsMap.get(indexId);
	}

	public PedigreePair getPair(int indexId) {
		Pair fhdPair = getFhdPair(indexId);
		if (fhdPair != null)
		{
			FhdIndividualConverter converter = new FhdIndividualConverter();
			Individual pedigreeA = converter.convert(fhdPair.getInd1());
			Individual pedigreeB = converter.convert(fhdPair.getInd2());
			PedigreeTarget target;
			if(fhdPair.isMatch()){
				target = PedigreeTarget.MATCH;
			}
			else{
				target = PedigreeTarget.MISMATCH;
			}
			PedigreeScore score = new PedigreeScore(target, fhdPair.getScore(), null);
			return new PedigreePair(pedigreeA, pedigreeB, score);
		} else
		{
			return null;
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}
}
